home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-16 | 2.7 KB | 109 lines | [TEXT/MPS ] |
- CASE OFF
-
- INCLUDE 'Traps.a'
- INCLUDE 'QuickEqu.a'
- INCLUDE 'SysEqu.a'
-
- FirstByte MAIN
- IMPORT Main, _DATAINIT
- ENTRY gGlobalsOffset
- bra.s Island
-
- dc.w 0 ; flags
- dc.l 0 ; resType
- dc.w 0 ; ID
- dc.w 0 ; version
- dc.l 0 ; refcon (THINK only)
-
- gGlobalsOffset dc.l 0 ; offset to globals
-
- Island
- bra Main
- lea _DATAINIT,A0 ; dummy line to reference _DATAINIT
-
- ;
- ; PROCEDURE UseGlobals(VAR save: SavedA5Rec); { Balance with DoneWithGlobals. }
- ;
- UseGlobals PROC EXPORT
- IMPORT GetSAA5
-
- move.l 4(sp),A0 ; get pointer to save record
- move.l A5,(A0) ; save A5
- move.l CurrentA5,4(A0) ; save low-memory value
- clr.l -(sp) ; make room for function result
- bsr.s GetSAA5 ; get our own A5
- move.l (sp)+,A5 ; make it real
- move.l A5,CurrentA5 ; make it really real
- move.l 4(sp),A0 ; get pointer to save record
- move.l (A0),A0 ; get host’s A5
- move.l (A0),(A5) ; copy his porthandle
- move.l (sp)+,(sp) ; remove parameters
- rts ; return to caller
-
-
- ;
- ; PROCEDURE CopyHostQD(thePort: Ptr; oldA5: Ptr); { Balance with DoneWithGlobals. }
- ; assumes that A5 has already been set up to our globals
- ;
- CopyHostQD PROC EXPORT
-
- returnAddress EQU 0
- oldA5 EQU returnAddress+4
- thePortPtr EQU oldA5+4
- parameterSize EQU thePortPtr-oldA5+4
-
- move.l oldA5(sp),A0 ; get oldA5
- move.l (A0),(A5) ; make (A5) point to thePort
-
- move.l (A0),A0 ; get host’s thePort pointer
- move.l thePortPtr(sp),A1 ; get our thePort pointer
- move.l #grafSize,D0 ; copy whole grafPort
- move.l D0,D1 ; since the pointers point near the
- subq.l #4,D1 ; ... end of the QD globals, move them
- sub.l D1,A0 ; ... down to point to the beginning
- sub.l D1,A2
- _BlockMove
-
- move.l (sp)+,A0 ; pop return address
- add #parameterSize,sp ; pop parameters
- jmp (A0) ; return to caller
-
- ;
- ; PROCEDURE DoneWithGlobals(restore: SaveA5Rec);
- ;
- DoneWithGlobals PROC EXPORT
-
- move.l (sp)+,A0 ; pull off return address
- move.l (sp)+,A1 ; address of record holding info
- move.l (A1),A5 ; first restore A5
- move.l 4(A1),CurrentA5 ; then restore low-memory value
- jmp (A0) ; return to caller
-
- ;
- ; FUNCTION GetSAA5: LONGINT;
- ;
- GetSAA5 PROC EXPORT
- IMPORT CalculateOffset
-
- move.l gGlobalsOffset,D0 ; have we done this before?
- bne.s @1 ; yes, so use cached value
- bsr.s CalculateOffset ; nope, so calculate it
- @1
- lea FirstByte,A0 ; get base address
- add.l A0,D0 ; add offset to top of globals
- move.l D0,4(sp) ; set function result
-
- rts ; return to caller
-
- CalculateOffset PROC
-
- lea FirstByte,A0 ; get pointer to us
- _RecoverHandle ; get handle to us
- _GetHandleSize ; find our size (= offset to end of globals)
- sub.l #32,D0 ; account for 32 bytes of appParms
- lea gGlobalsOffset,a0 ; get address to save result
- move.l D0,(A0) ; save this offset for later
- rts
-
- END
-